Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V3] Fix initially-hidden menuItem [mac/win] #4116

Open
wants to merge 15 commits into
base: v3-alpha
Choose a base branch
from

Conversation

IanVS
Copy link

@IanVS IanVS commented Mar 5, 2025

Description

Fixes #4088

This addresses the referenced issue, allowing menu items to be hidden at first, and then shown in response to some other event.

This also fixes a bug on Windows, which caused duplicate menu items to be added when calling .SetHidden(false) on a menu item that was not hidden.

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

I tested this by updating the menu example and checking that I can toggle the visibility of the menu item.

I tried in windows, but was not able to figure it out. I thought maybe removing the continue in the similar processMenu would have an effect, but it did not. In fact commenting out the entire processMenu function body seemed to have no effect. I don't know what's going on there.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features

    • Introduced a hidden menu item labeled "I was hidden" in the Demo submenu, which remains concealed by default.
    • Added a toggle option to show or hide the hidden menu item, enhancing interactivity.
    • Improved menu behavior across platforms for a more consistent user experience.
    • Added functionality to set menus dynamically for different operating systems (macOS, Windows, Linux).
  • Documentation

    • Added a new section detailing how to set the application menu across various platforms.

Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Walkthrough

This pull request introduces a hidden menu item labeled "I was hidden" in the Demo submenu and a new toggle menu item to switch its visibility. The toggle action is implemented via an OnClick event handler that calls SetHidden with the negated current state. The underlying menu processing for both macOS and Windows has been updated. For macOS, hidden items are now created and then set as hidden, while Windows menu processing has been restructured to map every menu item before checking and handling hidden states, reducing redundant state changes.


Changes

File Path Change Summary
v3/examples/menu/main.go Added a hidden menu item ("I was hidden") and a toggle item with an OnClick event to switch its visibility.
v3/pkg/application/menu_darwin.go Modified processMenu to create menu items for hidden items and call setHidden(true) on them instead of skipping.
v3/pkg/application/menuitem_windows.go,
v3/pkg/application/menu_windows.go,
v3/pkg/application/popupmenu_windows.go
Revised Windows menu handling to increment IDs and map items before visibility checks; updated setHidden to avoid redundant state changes and streamlined control flow in building menus.
v3/pkg/application/webview_window.go,
v3/pkg/application/webview_window_darwin.go,
v3/pkg/application/webview_window_linux.go,
v3/pkg/application/webview_window_windows.go
Added setMenu methods for different platforms to manage menu assignment based on the operating system.
v3/pkg/application/window.go Introduced SetMenu(menu *Menu) method in the Window interface to allow menu setting functionality.

Possibly related PRs


Poem

In code I hop with gleeful delight,
Hidden menus dance into sight.
A toggle click, a secret revealed,
In every function, wonder is sealed.
Hoppy code trails keep me light!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@IanVS IanVS changed the title V3: Fix initially-hidden menuItem [mac] [V3] Fix initially-hidden menuItem [mac] Mar 5, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
v3/pkg/application/menu_darwin.go (1)

102-104: Good fix for initially-hidden menu items

This change appropriately addresses the issue by ensuring hidden menu items are still created but visually suppressed using setHidden(true). Previously, it appears these items were skipped entirely during menu processing, making them impossible to show later.

This implementation allows for dynamic toggling of menu item visibility at runtime, which aligns with the PR objective of fixing initially-hidden menuItems on macOS.

This approach is architecturally sound as it maintains a consistent relationship between the application's menu model and the OS menu representation, regardless of visibility state.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96fa0d2 and d7dec9e.

📒 Files selected for processing (2)
  • v3/examples/menu/main.go (1 hunks)
  • v3/pkg/application/menu_darwin.go (1 hunks)
🔇 Additional comments (1)
v3/examples/menu/main.go (1)

47-52: Good demonstration of the hidden menu functionality

This implementation effectively demonstrates the new functionality:

  1. Creates a menu item that's initially hidden
  2. Provides a toggle mechanism to change visibility at runtime
  3. Uses the Hidden() method to check current state and negate it

The example serves as good documentation for how developers should implement this feature in their applications.

One small suggestion to enhance this example even further:

// Hidden menu item that can be unhidden
hidden := myMenu.Add("I was hidden").SetHidden(true)
myMenu.Add("Toggle hidden menu").OnClick(func(ctx *application.Context) {
    hidden.SetHidden(!hidden.Hidden())
+   // Update the toggle menu text to reflect current state
+   if hidden.Hidden() {
+       ctx.ClickedMenuItem().SetLabel("Show hidden menu")
+   } else {
+       ctx.ClickedMenuItem().SetLabel("Hide menu item")
+   }
})

IanVS added 2 commits March 6, 2025 08:49
Previously, when calling `.SetHidden(false)` on a menu item that was not hidden, a duplicate menu item was created.
@IanVS IanVS force-pushed the fix-hidden-menuitem branch from 5140cc0 to 42c6c2b Compare March 6, 2025 13:56
@IanVS IanVS changed the title [V3] Fix initially-hidden menuItem [mac] [V3] Fix initially-hidden menuItem [mac/win] Mar 6, 2025
IanVS added 2 commits March 6, 2025 13:58
And bring menu_windows into alignment with popupmenu_windows
@leaanthony leaanthony self-requested a review March 8, 2025 00:41
leaanthony
leaanthony previously approved these changes Mar 8, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/src/content/docs/changelog.mdx (1)

78-79: Changelog Entry for the New SetMenu() Feature
This new bullet point clearly documents the addition of the SetMenu() method on the window. Please verify that:

  • The changelog description accurately reflects the implementation and intended usage of SetMenu().
  • There is consistency across the documentation and examples regarding any platform-specific behaviors (for instance, if there are differences between macOS, Windows, and Linux).
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e529ae and fd9c37a.

📒 Files selected for processing (1)
  • docs/src/content/docs/changelog.mdx (1 hunks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants